print("Введите четырехзначное число:")
N = int(input(""))
if N <= 999 and N >= 10000:
	print(0)
else:
    a = str(N // 1000)
    b = str((N // 100) % 10)
    c = str((N // 10) % 10)
    d = str(N % 10)
    e = int(a+b)
    f = int(b+c)
    g = int(c+d)
    l = int(a+b+c)
    k = int(b+c+d)
    s = int(a + b + c + d)
    a = int(a)
    b = int(b)
    c = int(c)
    d = int(d)


    for i in range(2, a//2+1):
        if a % i == 0:
            a = 0
        else:
            i += 1
    for i in range(2, b//2+1):
        if b % i == 0:
            b = 0
        else:
            i += 1
    for i in range(2, c//2+1):
        if c % i == 0:
            c = 0
        else:
            i += 1
    for i in range(2, d//2+1):
        if d % i == 0:
            d = 0
        else:
            i += 1
    for i in range(2, e//2+1):
        if e % i == 0:
            e = 0
        else:
            i += 1
    for i in range(2, f//2+1):
        if f % i == 0:
             f = 0
        else:
            i += 1
    for i in range(2, g//2+1):
        if g % i == 0:
            g = 0
        else:
            i += 1
    for i in range(2, l//2+1):
        if l % i == 0:
            l = 0
        else:
            i += 1
    for i in range(2, k//2+1):
        if k % i == 0:
            k = 0
        else:
            i += 1
    for i in range(2, s//2+1):
        if s % i == 0:
            s = 0
        else:
            i += 1
print(max(a, b, c, d, e, f, g, l, k, s))



